package org.example.publisherrealtime.controller;


import org.example.publisherrealtime.bean.NameValue;
import org.example.publisherrealtime.service.PublisherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
public class publisherController {

    //获取方法
    @Autowired
    PublisherService publisherService;

    //明细查询
    @GetMapping("detailByItem")
    public Map<String, Object> detailByItem(@RequestParam("itemName") String itemName,
                                            @RequestParam("date") String date,
                                            @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                                            @RequestParam(value = "pageSize",required = false,defaultValue = "20")Integer pageSize) {
        Map<String, Object> searchResult = publisherService.doDetailByItem(itemName,date,pageNo,pageSize);
        return searchResult;
    }

    //传入值，传入商品名字，订单日期，和t这个可能是按年龄，也可能是性别
    @GetMapping("statByItem")
    public List<NameValue> statByItem(@RequestParam("itemName")String itemName ,
                                      @RequestParam("date") String date,
                                      @RequestParam("t") String t
                                      ){
        List<NameValue> items = publisherService.dostatByItem(itemName,date,t);
        return items;
    }

    //请求格式get
    @GetMapping ("dauRealtime")      //添加注解，获取参数
    public Map<String, Object> dauRealtime(@RequestParam("td") String td){
        //调用service层方法实现业务需求
        //使用方法对象调用方法
        Map<String ,Object> result =  publisherService.doDauRealtime(td);
        return result;
    }

}
